package com.ruoyi.queue.controller;

import java.util.List;

import com.ruoyi.queue.domain.QueWinBiz;
import com.ruoyi.queue.service.IQueBizService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.queue.domain.QueWin;
import com.ruoyi.queue.service.IQueWinService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排队窗口Controller
 *
 * @author Zliming
 * @date 2020-03-18
 */
@Controller
@RequestMapping("/queue/win")
public class QueWinController extends BaseController {
    private String prefix = "queue/win";

    @Autowired
    private IQueWinService queWinService;

    @RequiresPermissions("queue:win:view")
    @GetMapping()
    public String win() {
        return prefix + "/win";
    }

    /**
     * 查询排队窗口列表
     */
    @RequiresPermissions("queue:win:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QueWin queWin) {
        startPage();
        List<QueWin> list = queWinService.selectQueWinList(queWin);
        return getDataTable(list);
    }

    /**
     * 查询排队窗口列表
     */
    @RequiresPermissions("queue:win:list")
    @PostMapping("/listBiz")
    @ResponseBody
    public TableDataInfo listBiz(QueWin queWin) {
        startPage();
        List<QueWinBiz> list = queWinService.selectQueWinBizList(queWin.getId());
        return getDataTable(list);
    }

    /**
     * 导出排队窗口列表
     */
    @RequiresPermissions("queue:win:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QueWin queWin) {
        List<QueWin> list = queWinService.selectQueWinList(queWin);
        ExcelUtil<QueWin> util = new ExcelUtil<QueWin>(QueWin.class);
        return util.exportExcel(list, "win");
    }

    /**
     * 新增排队窗口
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存排队窗口
     */
    @RequiresPermissions("queue:win:add")
    @Log(title = "排队窗口", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QueWin queWin) {
        return toAjax(queWinService.insertQueWin(queWin));
    }

    /**
     * 修改排队窗口
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        QueWin queWin = queWinService.selectQueWinById(id);
        mmap.put("queWin", queWin);
        return prefix + "/edit";
    }

    /**
     * 修改保存排队窗口
     */
    @RequiresPermissions("queue:win:edit")
    @Log(title = "排队窗口", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QueWin queWin) {
        return toAjax(queWinService.updateQueWin(queWin));
    }

    /**
     * 删除排队窗口
     */
    @RequiresPermissions("queue:win:remove")
    @Log(title = "排队窗口", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(queWinService.deleteQueWinByIds(ids));
    }

    @Autowired
    private IQueBizService queBizService;
    /**
     * 选择用户
     */
    @GetMapping("/selectBiz/{winId}")
    public String selectUser(@PathVariable("winId") Long winId, ModelMap mmap)
    {
        mmap.put("biz", queBizService.selectQueBizById(winId));
        return prefix + "/selectBiz";
    }
}
